import type {Executor} from '../';
import type {GraphPO} from '../model/static/';

export class GraphController {

    constructor(private executor: Executor) {
    }

    /**
     * 对话graph抽取
     * 0 = "dashScopeAiVLChatModel"
     * 1 = "dashScopeAiChatModel"
     * 2 = "moonshotChatModel"
     * 3 = "ollamaChatModel"
     * 4 = "openAiChatModel"
     * 5 = "zhiPuAiChatModel"
     *
     * @parameter {GraphControllerOptions['createGraph']} options
     * - ques
     * @return [GraphPO]
     */
    createGraph: (options: GraphControllerOptions['createGraph']) => Promise<
        GraphPO
    > = async (options) => {
        let _uri = '/graph/extractQues';
        let _separator = _uri.indexOf('?') === -1 ? '?' : '&';
        let _value: any = undefined;
        _value = options.ques;
        _uri += _separator
        _uri += 'ques='
        _uri += encodeURIComponent(_value);
        _separator = '&';
        _value = options.modelName;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'modelName='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        return (await this.executor({uri: _uri, method: 'GET'})) as Promise<GraphPO>;
    }

    /**
     * 文件graph抽com.alibaba.dashscope.exception.ApiException: {"statusCode":400,"message":"Access denied, please make sure your account is in good standing.","code":"Arrearage","isJson":true,"requestId":"9018ebd9-25fe-98cc-8429-d901a0b8f528"}
     * 取
     * 0 = "dashScopeAiVLChatModel"
     * 1 = "dashScopeAiChatModel"
     * 2 = "moonshotChatModel"
     * 3 = "ollamaChatModel"
     * 4 = "openAiChatModel"
     * 5 = "zhiPuAiChatModel"
     *
     * @parameter {GraphControllerOptions['createGraph_2']} options
     * - file
     * @return [GraphPO]
     */
    createGraph_2: (options: GraphControllerOptions['createGraph_2']) => Promise<
        Array<GraphPO>
    > = async (options) => {
        let _uri = '/graph/extractGraphFile';
        let _separator = _uri.indexOf('?') === -1 ? '?' : '&';
        let _value: any = undefined;
        _value = options.modelName;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'modelName='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        const _formData = new FormData();
        const _body = options.body;
        _formData.append("file", _body.file);
        return (await this.executor({uri: _uri, method: 'POST', body: _formData})) as Promise<Array<GraphPO>>;
    }
}

export type GraphControllerOptions = {
    'createGraph': {
        ques: string,
        modelName?: string | undefined
    },
    'createGraph_2': {
        modelName?: string | undefined,
        body: {
            file: File
        }
    }
}